package com.example.test;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * TODO: 这里要写注释的!
 */
public class ExecutePoolServer {
    private ThreadPoolExecutor executor;

    public ExecutePoolServer(){
        this.executor= (ThreadPoolExecutor) Executors.newCachedThreadPool();
    }

    public void executeTask(ExecutePoolTask task){
        System.out.printf("Server: a new task has arrived.\n");
        executor.execute(task);
        System.out.printf("Server: pool size: %d\n", executor.getPoolSize());
        System.out.printf("Server: active count: %d\n", executor.getActiveCount());
        System.out.printf("Server: complete tasks: %d\n",executor.getCompletedTaskCount());
    }

    public void endServer(){
        executor.shutdown();
    }

}
